package com.admin.business.venusOrganizeInfo;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 公司信息表
 * @create: 2022-03-22 18:46:06
 **/
@Service("venusOrganizeInfo")
@Slf4j
public class VenusOrganizeInfoService{

    @Resource
    VenusOrganizeInfoDao venusOrganizeInfoDao;

    /**
     * 添加公司信息表,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - org_id:公司id
     *                   - org_short_name:企业简称
     *                   - org_established_time:成立时间
     *                   - org_office_local:办公地方
     *                   - org_enterprise_hot_line:企业热线
     *                   - org_enterprise_mailbox:机构邮箱
     *                   - org_institution_code:机构代码
     *                   - org_legal_person_id:法人id
     *                   - org_admin_id:管理员id
     *                   - org_business_license:营业执照
     *                   - org_name:名称
     *                   - org_create_bank:开户银行
     *                   - org_account:对公账户
     *                   - org_register_place:注册地点
     *                   - org_logo:公司logo
     *                   - org_synopsis:公司简介
     *                   - org_official_open:官网开通(1开通 2 不开通)
     *                   - org_second_domain:二级域名
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return addVenusOrganizeInfo(CDO cdoRequest) {
        venusOrganizeInfoDao.addVenusOrganizeInfo(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新公司信息表数据
     *
     * @param cdoRequest - id:主键
     *                   - org_id:公司id
     *                   - org_short_name:企业简称
     *                   - org_established_time:成立时间
     *                   - org_office_local:办公地方
     *                   - org_enterprise_hot_line:企业热线
     *                   - org_enterprise_mailbox:机构邮箱
     *                   - org_institution_code:机构代码
     *                   - org_legal_person_id:法人id
     *                   - org_admin_id:管理员id
     *                   - org_business_license:营业执照
     *                   - org_name:名称
     *                   - org_create_bank:开户银行
     *                   - org_account:对公账户
     *                   - org_register_place:注册地点
     *                   - org_logo:公司logo
     *                   - org_synopsis:公司简介
     *                   - org_official_open:官网开通(1开通 2 不开通)
     *                   - org_second_domain:二级域名
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return updateVenusOrganizeInfoById(CDO cdoRequest) {
        int affectedRows = venusOrganizeInfoDao.updateVenusOrganizeInfoById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，删除公司信息表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return deleteVenusOrganizeInfoById(CDO cdoRequest){
        int affectedRows = venusOrganizeInfoDao.deleteVenusOrganizeInfoById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除公司信息表数据
     *
     * @param cdoRequest
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return deleteVenusOrganizeInfo(CDO cdoRequest) {
        int affectedRows = venusOrganizeInfoDao.deleteVenusOrganizeInfo(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取公司信息表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusOrganizeInfoById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOrganizeInfoDao.getVenusOrganizeInfoById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取公司信息表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusOrganizeInfo(CDO cdoRequest) {
        CDO cdoMapperResult = venusOrganizeInfoDao.getVenusOrganizeInfo(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取公司信息表数据列表
     *
     * @param cdoRequest
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusOrganizeInfoList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOrganizeInfoDao.getVenusOrganizeInfoList(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOrganizeInfoDao.getVenusOrganizeInfoListCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取公司信息表数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusOrganizeInfoListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOrganizeInfoDao.getVenusOrganizeInfoListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOrganizeInfoDao.getVenusOrganizeInfoListByConditionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
